#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct TreeNode {
    char val;
    struct TreeNode* left;
    struct TreeNode* right;
};

// 根据前序和中序遍历结果构造二叉树
struct TreeNode* buildTree(char* preorder, char* inorder, int preStart, int preEnd, int inStart, int inEnd) {
    if (preStart > preEnd || inStart > inEnd) {
        return NULL;
    }

    // 根节点值为前序遍历结果的第一个字符
    char rootValue = preorder[preStart];
    struct TreeNode* root = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    root->val = rootValue;

    // 在中序遍历结果中找到根节点的位置
    int rootIndex;
    for (rootIndex = inStart; rootIndex <= inEnd; rootIndex++) {
        if (inorder[rootIndex] == rootValue) {
            break;
        }
    }

    // 递归构造左子树和右子树
    int leftTreeSize = rootIndex - inStart;
    root->left = buildTree(preorder, inorder, preStart + 1, preStart + leftTreeSize, inStart, rootIndex - 1);
    root->right = buildTree(preorder, inorder, preStart + leftTreeSize + 1, preEnd, rootIndex + 1, inEnd);

    return root;
}

// 后序遍历二叉树并输出结果
void postorderTraversal(struct TreeNode* root) {
    if (root == NULL) {
        return;
    }

    postorderTraversal(root->left);
    postorderTraversal(root->right);
    printf("%c", root->val);
}

int main() {
    char preorder[100];
    char inorder[100];
    while (scanf("%s %s", preorder, inorder) == 2) {
        int preLen = strlen(preorder);
        int inLen = strlen(inorder);
        // 构造二叉树
        struct TreeNode* root = buildTree(preorder, inorder, 0, preLen - 1, 0, inLen - 1);
        // 后序遍历并输出结果
        postorderTraversal(root);
        printf("\n");
    }
    return 0;
}